<template>
  <div>
    <avue-crud
        v-if="tableOption"
        v-bind="bindVal"
        v-on="onEvent"
        v-model:page="page"
        v-model="startForm">
      <!-- 菜单按钮 -->
      <template slot="menuLeft">
        <el-button type="primary" v-if="getBtnPermission('downloadTemplateBtn',null,null,false)"
                   @click="downloadTemplate()" size="small">下载导入模板
        </el-button>
        <el-button type="primary" v-if="getBtnPermission('exportExcelBtn',null,null,false)" @click="handlerImportExcel"
                   size="small">导入excel
        </el-button>
        <el-button type="primary" v-if="getBtnPermission('importExcelBtn',null,null,false)"
                   @click="downloadexportExcel()"
                   size="small">导出excel
        </el-button>
      </template>
      <template v-for="(column,index) in columns" :slot="column.prop" slot-scope="{type,size,row}">
        <component :is="column.columnComponent" :row="row" :column="column" :rowKey="column.prop"
        ></component>
      </template>
      <template #menu="{type,size,row}">
        <el-button icon="el-icon-edit" link :size="size" @click="editUserRole(row)" :type="type">用户角色
        </el-button>
        <el-button icon="el-icon-edit" link :size="size" @click="editUserPwd(row)" :type="type">密码重置
        </el-button>
      </template>
    </avue-crud>
    <select-user-roles ref="selectUserRoles"></select-user-roles>
    <start-update-user-pwd-dialog ref="updateUserPwdDialog"
                                  :update-pwd-api="updateUserPassword"></start-update-user-pwd-dialog>
    <!--    &lt;!&ndash; 数据导入插件 &ndash;&gt;-->
    <import-excel ref="importExcel"
                  upload-name="数据表配置导入"
                  :upload-key="pageOption.name"
                  :option="pageOption"
                  @importSuccess="refreshChange">

    </import-excel>
  </div>
</template>

<script>

import SelectUserRoles from "./SelectUserRoles.vue";
import startUpdateUserPwdDialog from "components/start-components/startDpdateUserPwd/startUpdateUserPwdDialog.vue";
import ImportExcel from "@/components/common/ImportExcel.vue";
import {createStaticMixin} from '@/mixins/startCrud';
import * as userApi from "@/api/sys/userApi";
import {updateUserPassword} from "@/api/sys/userApi";
import userOption from "@/option/sys/userOption";

const option = {}
option.option = userOption
option.api = userApi
export default {
  mixins: [createStaticMixin(option)],
  name: "userList",
  components: {
    ImportExcel,
    SelectUserRoles,
    startUpdateUserPwdDialog,
  },
  props: {
    userSearchParam: {
      type: Object,
      default: () => {
        return {}
      },
    }
  },

  methods: {
    updateUserPassword,
    beforeLoadDataSource(search) {
      if (!this.userSearchParam) {
        return search;
      }
      return Object.assign({}, search, this.userSearchParam)
    },
    searchReRestBefore(params, done) {
      this.$emit("searchReset", params, done);
    },
    beforeRowUpdate(row, index) {
    },
    editUserRole(row) {
      this.$refs.selectUserRoles.show(row.id)
    },
    editUserPwd(row) {
      this.$refs.updateUserPwdDialog.show(row.id)
    }
  }
}
</script>

<style scoped>

</style>
